package com.daodway.designpattern.statepattern;

import java.util.HashMap;
import java.util.Map;

public class EntityManager {
	private static EntityManager instance=null;
	private EntityManager(){}
	public static EntityManager Instace(){
		if(instance==null){
			instance=new EntityManager();
		}
		return instance;
	}
	private Map<Long,BaseGameEntity> entityMap=new HashMap<Long,BaseGameEntity>();
	
	public void RegisterEntity(BaseGameEntity newEntity){
		entityMap.put(newEntity.ID(), newEntity);
	}
	public BaseGameEntity getEntityFromId(Long id){
		BaseGameEntity entity=null;
		for(Long idKey:entityMap.keySet()){
			if(id.equals(idKey)){
				entity=entityMap.get(idKey);
			}
		}
		return entity;
	}
	public void RemoveEntity(BaseGameEntity pEntity){
		for(Long idKey:entityMap.keySet()){
			if(pEntity.ID()==idKey){
				entityMap.remove(idKey);
			}
		}
	}
	public Map<Long, BaseGameEntity> getEntityMap() {
		return entityMap;
	}
	public void setEntityMap(Map<Long, BaseGameEntity> entityMap) {
		this.entityMap = entityMap;
	}
	
	
}
